package practice.tmp;

import java.util.*;

public class Solution491 {
    List<List<Integer>> res = new ArrayList<>();

    List<Integer> tmp = new LinkedList<>();

    public List<List<Integer>> findSubsequences(int[] nums) {
        back(nums, 0);
        return res;
    }

    public void back(int[] nums, int index) {
        if (tmp.size() >= 2) res.add(new ArrayList<>(tmp));
        if (index == nums.length) return;
        HashSet<Integer> set = new HashSet<>();
        for (int i = index; i < nums.length; i++) {
            if (!set.contains(nums[i]) && (tmp.isEmpty() || nums[i] >= tmp.get(tmp.size() - 1))) {
                tmp.add(nums[i]);
                set.add(nums[i]);
                back(nums, i + 1);
                tmp.remove(tmp.size() - 1);
            }
        }
    }

}
